#define uploadify()
	<form  method="post" enctype="multipart/form-data">
		<input type="file" name="file_upload" id="_#(x.index??)_file_upload"/>
		<div class="form-group">
			<div class="col-sm-12" id="_#(x.index??)_file">
			
			</div>
		</div>
		<!-- <div class="form-group" style="display:none;">
			<textarea  id="#(x.index??)_editor" name="#(x.index??)_editor" ></textarea>
		</div> -->
		<input type="hidden" id="_#(x.index??)" data-type=uploadify name="token_#(table??x.table).#(x.index??)"  value=""  class="form-control"/>
	</form>
	<link rel="stylesheet" type="text/css" href="/static/uploadify/uploadify.css">
	<script src="/static/uploadify/jquery.uploadify.min.js" type="text/javascript"></script>
		<script type="text/javascript">
		$(function(){
			$("#_#(x.index??)_file_upload").uploadify({
				###校验数据
				'swf' : '/static/uploadify/uploadify.swf', ###指定上传控件的主体文件
				###'uploader' : '/uploadify/uploadBlob',###上传保存到blob字段并返回读取接口
				'uploader' : '/kindeditor/upload',###上传保存文件并返回路径
				'auto' : true, ###自动上传
				'buttonImage' : '/static/uploadify/uploadify-upload.png', ###浏览按钮背景图片
				'cancelImage' : '/static/uploadify/uploadify-cancel.png',
				'multi' : true,###单文件上传
				'fileTypeExts' : '*.gif; *.jpg; *.png; *.flv; *.avi;*.doc; *.mp4;*.pdf;*.xls;*.xlsx;*.mp3', ###允许上传的文件后缀
				'fileSizeLimit' : '5MB', ###上传文件的大小限制，单位为B, KB, MB, 或 GB
				'successTimeout' : 30,###成功等待时间
				'formData': {'dir':'file','uploadType':"#(x.uploadType)",'typeCode':"#(x.typeCode)",'attachId':"#(x.attachId)",'table':"#(x.table)"},
				'onUploadSuccess' : function(file, data, response) {
					###每成功完成一次文件上传时触发一次
					var file=eval("["+data+']')[0];
					if(file.error==1){
						layer_alert('不正确的文件类型!', "warn");
						return;
					}
					var _name = $("#_#(x.index??)").attr("name").replace("token_", "");
					$("#_#(x.index??)").attr("name", _name);
					if($("#_#(x.index??)").val()==""){
						$("#_#(x.index??)").val(file.fileId);
					}else{
						$("#_#(x.index??)").val($("#_#(x.index??)").val()+","+file.fileId);
					}
					$("#_#(x.index??)_file").append(_#(x.index??)_getFile(file.url, file.fileId, file.fileName));
                    $("#form_token").val(1);
				},
				'onUploadError' : function(file, data, response) {
					###当上传返回错误时触发
					
				}
			});
		});
		function _#(x.index??)_inituploadifyUpload(ids, type){
			$.ajax({
		        type: "post",
		        url: "/kindeditor/initfile",
		        dataType: "json",
		        async: false,
		        data: {ids : ids},
		        success: function(data) {
		        	if(data.state == 'ok'){
						var file = data.data;
						for(var x = 0; x < file.length; x++){
							var id = file[x].id;
							var name = file[x].name;
							var url = "/kindeditor/renderFile/" + id;
							if(type == "edit"){
								$("#_#(x.index??)_file").append(_#(x.index??)_getFile(url, id, name));
							}
							else{
								$("#_#(x.index??)_file_upload").css("display", "none");
								$("#_#(x.index??)_file").append(_#(x.index??)_getViewFile(url, id, name));
							}
							
						}
					}
					else{
						layer.alert("加载附件失败", {
							icon : 7
						});
					}
		        }
		    });
		}
		
		function _#(x.index??)_getFile(url, id, name){
			var html = [];
			html.push('<div class="alert alert-block alert-success" id="_#(x.index??)_file_' + id + '">');
			html.push("	<button type=\"button\" class=\"close\" onclick=\"_#(x.index??)_deleteFile(" + id + ",'" + name + "')\">");
			html.push('		<i class="ace-icon fa fa-times"></i>');
			html.push('	</button>');
			html.push('	<i class="ace-icon fa fa-cloud-download green"></i>');
			html.push('	<strong class="green">');
			html.push('		<a class="green" href="'+url+'" target="_blank">' + name + '</a>');
			html.push('	</strong>');
			html.push('</div>');
			return html.join('');
		}
		
		function _#(x.index??)_getViewFile(url, id, name){
			var html = [];
			html.push('<div class="alert alert-block alert-success" id="#(x.index??)_file_' + id + '">');
			html.push('	<i class="ace-icon fa fa-cloud-download green"></i>');
			html.push('	<strong class="green">');
			html.push('		<a class="green" href="'+url+'" target="_blank">' + name + '</a>');
			html.push('	</strong>');
			html.push('</div>');
			return html.join('');
		}
		
		
		function _#(x.index??)_deleteFile(id, name){
			 layer.confirm('是否删除选中文件 (' + name + ') ？', {
	                icon: 3,
	                btn: ['确定', '取消']
	            }, function () {
	           		$("#_#(x.index??)_file_" + id).remove();
	           		var ids = $("#_#(x.index??)").val();
	           		
	           		var idArr = ids.split(",");
	           		if(_contains(idArr, id)){
	           			idArr.remove(id);
	           		}
	           		
					var newids = idArr.join(",");
	           		$("#_#(x.index??)").val(newids);
	           	 	$("#form_token").val(1);
	           		layer.msg("删除成功!", {icon:1});
	            }, function () {
	            });
		}
		
		function _contains(arr, obj){
			for (var i = 0; i < arr.length; i++) {
		        if (obj == arr[i] || obj.toString() == arr[i]) {
		            return true;
		        }
		    }
		    return false;
		}
	</script>
#end
